package com.cbb.springcloud.common.result;

import com.cbb.springcloud.common.enums.ResultEnum;

import java.util.Collection;

/**
 * 返回值 Util
 *
 * @author chaibb
 * @date 2021-07-12 20:15:22
 */
public class ResultUtil {

    public static <T> Result<T> success(Integer code, String message, T data) {
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setMessage(message);
        result.setData(data);
        return result;
    }

    public static Result<String> success() {
        return success("");
    }

    public static Result<String> success(Integer code, String msg) {
        return success(code, msg, null);
    }

    public static Result<String> error(Integer code, String msg) {
        return success(code, msg, null);
    }

    public static Result<String> error(String msg) {
        return error(ResultEnum.UNKNOWN_ERROR.getCode(), msg);
    }


    public static <T> Result<T> success(T data) {
        return success(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg(), data);
    }

}
